import mmap,time

# 创建共享内存文件
with open('shared_mem', 'w+b') as f:
    f.truncate(1024)
a=0
# 写入数据
with open('shared_mem', 'r+b') as f:
    mm = mmap.mmap(f.fileno(), length=1024)
    while 1:
        time.sleep(0.0000001)
        a+=1
        v=f'1{a}'.encode('utf-8')
        mm[0:len(v)] = v
        while 1:
            time.sleep(0.00000001)
            if mm[0]==50:
                # v=f'3{a}'.encode('utf-8')
                # mm[0:len(v)] = v
                break
mm.close()
